<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of sealplayer
 *
 * @author Samuel
 */
class Registmail_controller extends Controller {
    private $areaList;	//区号列表
    private $areaAddr2ID; //大区地址到大区ID的映射
    private $wholeServerHost;

    function _init()
    {
        check_level(50, segment(0), segment(1), segment(2, 'index'));

        $config = get_config();
        $this->wholeServerHost = $config['host_url'];

        $server_list=get_server_list();
         foreach($server_list as $k=>$row) {
            $this->areaList[$row['SvrAddr']] = $row['SvrID']."-".$row['SvrName'][1];
            $this->areaAddr2ID[$row['SvrAddr']]=$row['SvrID'];
        }
    }

    function index()
    {
        if(is_submit())
        {
            $rowdata = $_POST['row'];

            $post_data['SessionID']="ewewqw";
            $post_data['SessionKey']="wqqew";

            $post_data['ID']=(int)$rowdata['id']; //新手注册奖励ID
            $post_data['Title']=(string)$rowdata['title'];
            $post_data['Msg'] = (string)$rowdata['msg'];

            $itemcount = 0;
            foreach ($rowdata['item'] as $k=>$v){
                $item=array("ID"=>(int)$v,"Num"=>(int)$rowdata['amount'][$k]);
                $post_data['ItemLst'][$k]=$item;
                if ($itemcount ==0){
                    $mailloginfo['itemid0'] = (int)$v;
                    $mailloginfo['amount0'] = (int)$rowdata['amount'][$k];
                }else if  ($itemcount ==1){
                    $mailloginfo['itemid1'] = (int)$v;
                    $mailloginfo['amount1'] = (int)$rowdata['amount'][$k];
                }else if  ($itemcount ==2){
                    $mailloginfo['itemid2'] = (int)$v;
                    $mailloginfo['amount2'] = (int)$rowdata['amount'][$k];
                }else if  ($itemcount ==3){
                    $mailloginfo['itemid3'] = (int)$v;
                    $mailloginfo['amount3'] = (int)$rowdata['amount'][$k];
                }

                $itemcount += 1;
            }
            
            $post_data['SvrID'] = (int)$this->areaAddr2ID[$rowdata['area_host']];

            $strResult = vpost($this->wholeServerHost.'set_regist_award',3,json_encode($post_data));

            $result=json_decode($strResult,true);
            //操作失败或者连接失败
            if($result['RetCode'] == 0)
            {
                insert_log(translate('MENU_SEND_OBJECT'),translate('ADD'),NULL,$rowdata);
                echo "<script>alert('".translate('C_TIPS_SUCCESS_TEXT')."')</script>";
            }
            else {
                //unset($rowdata);
                if ($result['RetCode'] == 1) {
                    echo "<script>alert('" . translate('ROLE_FIGHT_VALUE_ERROR') . "')</script>";
                } else if ($result['RetCode'] == 2) {
                    echo "<script>alert('" . translate('ROLE_LEVEL_ERROR') . "')</script>";
                } else if ($result['RetCode'] == 3) {
                    echo "<script>alert('" . translate('ROLE_ROLE_ID_ERROR') . "')</script>";
                }
            }
        }

        $this->view->assign("arealist", $this->form->select("row[area_host]", $this->areaList, '', array('id' => 'area_host')));
        $this->view->display("seal/registmail/send");
    }

}

?>
